home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / et / et3_0-a1.lha / et3 / src / PictPort.C < prev    next >
C/C++ Source or Header  |  1992-05-12  |  6KB  |  354 lines

  1. #ifdef __GNUG__
  2. #pragma implementation
  3. #endif
  4.  
  5. #include "PictPort.h"
  6.  
  7. #include "Class.h"
  8. #include "String.h"
  9. #include "Picture.h"
  10. #include "ObjArray.h"
  11. #include "MemBuf.h"
  12.  
  13. NewMetaImpl0(PictPort, PrintPort);
  14.  
  15. //---- PictPort ----------------------------------------------------------------
  16.  
  17. PictPort::PictPort(Picture *p) : PrintPort("PICT")
  18. {
  19.     hascolor= TRUE;
  20.     pict= p;
  21.     DevOpenPage(0);
  22. }
  23.  
  24. PictPort::~PictPort()
  25. {
  26.     FlushMyText();
  27.     PutCode(cPicEnd);
  28.     if (pict)
  29.     pict->Set(pagebbox, (byte*) pagebuf->Base(), (int) pagebuf->tell(), map);
  30.     SafeDelete(pagebuf);
  31. }
  32.  
  33. void PictPort::DevOpenPage(int)
  34. {
  35.     pagebuf= new MemBuf;
  36.     map= new ObjArray;
  37.  
  38.     lastfont= 0;
  39.     lastextent= lastpos= gPoint0;
  40.     lastdia= gPoint0;
  41.     lastpsz= 1;
  42.     laststartangle= lastendangle= 0;
  43.     lastcap= eDefaultCap;
  44.     for (int i= 0; i < map->Size(); i++)
  45.     map->AtPut(i, 0);
  46.     //pagebuf->seek(0);
  47. }
  48.  
  49. void PictPort::DevClosePage()
  50. {
  51.     FlushMyText();
  52.     PutCode(cPicEnd);
  53.     if (pict)
  54.     pict->Set(pagebbox, (byte*) pagebuf->Base(), (int) pagebuf->tell(), map);
  55. }
  56.  
  57. void PictPort::PutInt(int i)
  58. {
  59.     /*
  60.     PutByte(i >> 24);
  61.     PutByte(i >> 16);
  62.     PutByte(i >> 8);
  63.     PutByte(i);
  64.     */
  65.     pagebuf->sputn((char*) &i, 4);
  66. }
  67.  
  68. void PictPort::PutShort(short s)
  69. {
  70.     /*
  71.     PutByte(i >> 8);
  72.     PutByte(i);
  73.     */
  74.     pagebuf->sputn((char*) &s, 2);
  75. }
  76.  
  77. void PictPort::PutPoint(byte code, Point p)
  78. {
  79.     if (p.x != 0) {
  80.     if (p.x >= -128 && p.x < 128) {
  81.         code+= 1 << 2;
  82.     } else if (p.x >= -32768 && p.x < 32768) {
  83.         code+= 2 << 2;
  84.     } else {
  85.         code+= 3 << 2;
  86.     }
  87.     }
  88.     if (p.y != 0) {
  89.     if (p.y >= -128 && p.y < 128) {
  90.         code+= 1;
  91.     } else if (p.y >= -32768 && p.y < 32768) {
  92.         code+= 2;
  93.     } else {
  94.         code+= 3;
  95.     }
  96.     }
  97.     PutCode(code);
  98.     if (p.x != 0) {
  99.     if (p.x >= -128 && p.x < 128) {
  100.         PutByte(p.x);
  101.     } else if (p.x >= -32768 && p.x < 32768) {
  102.         PutShort(p.x);
  103.     } else {
  104.         PutInt(p.x);
  105.     }
  106.     }
  107.     if (p.y != 0) {
  108.     if (p.y >= -128 && p.y < 128) {
  109.         PutByte(p.y);
  110.     } else if (p.y >= -32768 && p.y < 32768) {
  111.         PutShort(p.y);
  112.     } else {
  113.         PutInt(p.y);
  114.     }
  115.     }
  116. }
  117.  
  118. void PictPort::PutPos(Point pos)
  119. {
  120.     Point delta= pos-lastpos;
  121.     lastpos= pos;
  122.     
  123.     if (delta.x >= -32 && delta.x < 32 && delta.y == 0)
  124.     PutCode(cPicXMove0+delta.x+32);
  125.     else
  126.     PutPoint(cPicMove, delta);
  127. }
  128.  
  129. void PictPort::PutRect(Rectangle *r)
  130. {
  131.     PutPos(r->origin);
  132.     
  133.     Point delta= r->extent - lastextent;
  134.  
  135.     if (delta.x != 0 || delta.y != 0) {
  136.     lastextent= r->extent;
  137.     PutPoint(cPicExtent, delta);
  138.     }
  139. }
  140.  
  141. void PictPort::PutInk()
  142. {
  143.     if (lastink != lastink2) {
  144.     PutCode(cPicInk);
  145.     PutShort(map->Index(lastink2= lastink));
  146.     }
  147. }
  148.  
  149. void PictPort::PutSize(int s)
  150. {
  151.     if (s >= 0 && lastpsz != s) {
  152.     PutCode(cPicPensize);
  153.     PutByte(s);
  154.     lastpsz= s;
  155.     }
  156. }
  157.  
  158. void PictPort::PutCap(GrLineCap cap)
  159. {
  160.     if (cap != lastcap) {
  161.     PutCode(cPicPenCap);
  162.     PutByte(cap);
  163.     lastcap= cap;
  164.     }
  165. }
  166.  
  167. void PictPort::PutAngle(int s, int e)
  168. {
  169.     if (s != laststartangle) {
  170.     PutCode(cPicStartAngle);
  171.     PutShort(s);
  172.     laststartangle= s;
  173.     }
  174.     if (e != lastendangle) {
  175.     PutCode(cPicEndAngle);
  176.     PutShort(e);
  177.     lastendangle= e;
  178.     }
  179. }
  180.  
  181. void PictPort::PutDia(Point e)
  182. {
  183.     if (e != lastdia) {
  184.     PutPoint(cPicCornerDia, e);
  185.     lastdia= e;
  186.     }
  187. }
  188.  
  189. void PictPort::DevClip(Rectangle clr)
  190. {
  191.     PutRect(&clr);
  192.     PutCode(cPicClip);
  193. }
  194.  
  195. void PictPort::DevStrokeLine(int psz, Rectangle *r, GrLineCap cap, Point p1, Point p2)
  196. {
  197.     Merge(r);
  198.     PutInk();
  199.     p2-= p1;
  200.     PutSize(psz);
  201.     PutCap(cap);
  202.     PutPos(p1);
  203.     PutPoint(cPicLine, p2);
  204.     lastpos+= p2;
  205. }
  206.  
  207. extern Ink *gTbInk;
  208.  
  209. void PictPort::DevShowChar(Font *fp, Point, byte c, Rectangle *r)
  210. {
  211.     Merge(r);
  212.  
  213.     lastink= gTbInk;
  214.     PutInk();
  215.     PutPos(r->origin+Point(0, fp->Ascender()));
  216.     if (lastfont != fp) {
  217.     PutCode(cPicFont);
  218.     PutShort(map->Index(lastfont= fp));
  219.     }
  220.     if (c >= 128 || c < 32)   // need escape
  221.     PutCode(cPicEsc);
  222.     PutChar(c);
  223.     lastpos.x+= fp->Width(c);
  224. }
  225.  
  226. void PictPort::DevStrokeRect(int psz, Rectangle *r)
  227. {
  228.     Merge(r);
  229.     PutInk();
  230.     PutRect(r);
  231.     PutSize(psz);
  232.     PutCode(cPicStrokeRect);
  233. }
  234.  
  235. void PictPort::DevFillRect(Rectangle *r)
  236. {
  237.     Merge(r);
  238.     PutInk();
  239.     PutRect(r);
  240.     PutCode(cPicFillRect);
  241. }
  242.  
  243. void PictPort::DevStrokeOval(int psz, Rectangle *r)
  244. {
  245.     Merge(r);
  246.     PutInk();
  247.     PutRect(r);
  248.     PutSize(psz);
  249.     PutCode(cPicStrokeOval);
  250. }
  251.  
  252. void PictPort::DevFillOval(Rectangle *r)
  253. {
  254.     Merge(r);
  255.     PutInk();
  256.     PutRect(r);
  257.     PutCode(cPicFillOval);
  258. }
  259.  
  260. void PictPort::DevStrokeRRect(int psz, Rectangle *r, Point dia)
  261. {
  262.     Merge(r);
  263.     PutInk();
  264.     PutRect(r);
  265.     PutSize(psz);
  266.     PutDia(dia);
  267.     PutCode(cPicStrokeRRect);
  268. }
  269.  
  270. void PictPort::DevFillRRect(Rectangle *r, Point dia)
  271. {
  272.     Merge(r);
  273.     PutInk();
  274.     PutRect(r);
  275.     PutDia(dia);
  276.     PutCode(cPicFillRRect);
  277. }
  278.  
  279. void PictPort::DevStrokeWedge(int psz, GrLineCap cap, Rectangle *r, int s, int d)
  280. {
  281.     Merge(r);
  282.     PutInk();
  283.     PutRect(r);
  284.     PutSize(psz);
  285.     PutCap(cap);
  286.     PutAngle(s, d);
  287.     PutCode(cPicStrokeWedge);
  288. }
  289.  
  290. void PictPort::DevFillWedge(Rectangle *r, int s, int d)
  291. {
  292.     Merge(r);
  293.     PutInk();
  294.     PutRect(r);
  295.     PutAngle(s, d);
  296.     PutCode(cPicFillWedge);
  297. }
  298.  
  299. void PictPort::DevStrokePolygon(Rectangle *r, Point *pts, int n, GrPolyType t,
  300.                             int psz, GrLineCap cap)
  301. {
  302.     Merge(r);
  303.     PutPos(r->origin);
  304.     PutInk();
  305.     PutSize(psz);
  306.     PutCap(cap);
  307.     PutCode(cPicStrokePoly);
  308.     PutByte(t);
  309.     PutShort(n);
  310.     for (int i= 0; i < n; i++)
  311.     PutPoint(0, pts[i]);
  312. }
  313.  
  314. void PictPort::DevFillPolygon(Rectangle *r, Point *pts, int n, GrPolyType t)
  315. {
  316.     Merge(r);
  317.     PutPos(r->origin);
  318.     PutInk();
  319.     PutCode(cPicFillPoly);
  320.     PutByte(t);
  321.     PutShort(n);
  322.     for (int i= 0; i < n; i++)
  323.     PutPoint(0, pts[i]);
  324. }
  325.  
  326. void PictPort::DevShowBitmap(Rectangle *r, struct Bitmap *bmp)
  327. {
  328.     Merge(r);
  329.     PutInk();
  330.     PutRect(r);
  331.     PutCode(cPicShowBitmap);
  332.     PutShort(map->Index(bmp));
  333. }
  334.  
  335. void PictPort::DevShowPicture(Rectangle *r, Picture *pict)
  336. {
  337.     Merge(r);
  338.     PutRect(r);
  339.     PutCode(cPicShowPicture);
  340.     PutShort(map->Index(pict));
  341. }
  342.  
  343. void PictPort::DevGiveHint(int code, int len, void *vp)
  344. {
  345.     PutCode(cPicHint);
  346.     PutInt(code);
  347.     if (vp) {
  348.     PutInt(len);
  349.     pagebuf->sputn((char*) vp, len);
  350.     } else
  351.     PutInt(0);
  352. }
  353.  
  354.